#!/usr/bin/env python3
import re

def fix_this_references(file_path):
    """修复WebViewActivity.kt中的this引用问题"""
    
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # 修复AlertDialog.Builder(this)
    content = re.sub(r'AlertDialog\.Builder\(this\)', 'AlertDialog.Builder(this@WebViewActivity)', content)
    
    # 修复Toast.makeText(this, 
    content = re.sub(r'Toast\.makeText\(this,', 'Toast.makeText(this@WebViewActivity,', content)
    
    # 修复Intent(this, 
    content = re.sub(r'Intent\(this,', 'Intent(this@WebViewActivity,', content)
    
    # 修复getSystemService中的this
    content = re.sub(r'getSystemService\(android\.content\.Context\.', 'this@WebViewActivity.getSystemService(android.content.Context.', content)
    
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(content)
    
    print("✅ 已修复所有this引用问题")

if __name__ == "__main__":
    fix_this_references("app/src/main/java/com/mumu/xiaodu/WebViewActivity.kt") 